import { EarthOut } from "../GameData";
import GameManager from "../GameManager";
import WTool, { TweenType } from "../WTool";
import { ZTool } from "../ZTool";

const { ccclass, property } = cc._decorator;

@ccclass
export default class Out extends cc.Component {

    direction: number = 0;//行进方向
    cycle: number = 0;//行进周期

    onLoad() {
        switch (this.node.name) {
            case GameManager.Instance.GetEnumKey(EarthOut, EarthOut.Earth_Airplane):
                {
                    this.direction = 1;
                    this.cycle = ZTool.GetRandom(60, 70);
                }
                break;
            case GameManager.Instance.GetEnumKey(EarthOut, EarthOut.Earth_Car):
                {
                    this.direction = 1;
                    this.cycle = ZTool.GetRandom(100, 120);
                }
                break;
            case GameManager.Instance.GetEnumKey(EarthOut, EarthOut.Earth_Copter):
                {
                    this.direction = -1;
                    this.cycle = ZTool.GetRandom(80, 90);
                }
                break;
            case GameManager.Instance.GetEnumKey(EarthOut, EarthOut.Earth_People):
                {
                    this.direction = -1;
                    this.cycle = ZTool.GetRandom(130, 150);
                }
                break;
        }
        WTool.Tween_AngleForever(this.node, this.cycle, this.direction * 360, () => {
            this.node.angle = 0;
        })
        cc.tween(this.node.children[0])
            .by(0.3, { position: cc.v3(0, 3), scaleX: -0.05, scaleY: 0.1 })
            .by(0.3, { position: cc.v3(0, -3), scaleX: 0.05, scaleY: -0.1 })
            .union()
            .repeatForever()
            .start()
    }

    start() {

    }

    // update (dt) {}
}
